﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Controls;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>
    public partial class GB02 : DocumentBase
    {
        #region-------------Properties-----------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        //private Dictionary<string, object> dicQueryParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        GB02Data m_Data, m_DataX;
        GB02Report m_rpt;
        public DataSet dsParamaters;
        
        #endregion
        public GB02()
        {
            InitializeComponent();
            this.Name = "纱线库存表";
        }
        private void ItemsControls_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        } 
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
           

            this.dicParamater = dicParamater;
            OracleDB = (OracleConnection)dicParamater["OracleDB"];
            dsParamaters = (DataSet)dicParamater["dsParamaters"];
            proxy = (IntexReptServBLClient)dicParamater["proxy"];
            orlReadCommand = this.OracleDB.CreateCommand();
            orlReadCommand.Parameters.Add("OrdNum", OracleType.NVarChar).Value = "";
            m_Data = new GB02Data();
            m_Data.OracleDB = this.OracleDB;
            m_Data.proxy = this.proxy;
            m_rpt = new GB02Report(dicParamater);
        }

        private void InitDataBinding()
        {
            try
            {
                setUI = (DataSet)TryFindResource("setUI");
                if (setUI == null)
                {
                    setUI = new DataSet();
                }
                this.setUI.Tables.Clear();
                setUI.AcceptChanges();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            InitDataBinding();
            try
            {
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = m_Data.BuildData();
                    setUI.Clear();
                    setUI.Merge(setResult);
                    this.MasterData.DataContext = setUI;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnReport_Click(object sender, RoutedEventArgs e)
        {
            m_DataX = new GB02Data(dicParamater);
            m_DataX.OracleDB = this.OracleDB;
            m_DataX.proxy = this.proxy;
            m_rpt.exAgent = m_DataX.exAgent;
            m_rpt.dsSource = setUI;
            m_rpt.REPORT2EXCEL("EXCEL");
        } 
    }
}